package com.itheima.tliaswebmanagement.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tliaswebmanagement.mapper.ClazzMapper;
import com.itheima.tliaswebmanagement.pojo.common.PageResult;
import com.itheima.tliaswebmanagement.pojo.dto.ClazzPageQueryDTO;
import com.itheima.tliaswebmanagement.pojo.dto.EmpPageQueryDTO;
import com.itheima.tliaswebmanagement.pojo.entity.Clazz;
import com.itheima.tliaswebmanagement.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description ClazzServiceImpl
 * @Author ziguan ling
 * @Date 2025--01--03
 */
@Service
@Slf4j
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    ClazzMapper clazzMapper;

    @Override
    public PageResult<Clazz> page(ClazzPageQueryDTO clazzPageQueryDTO) {


        PageHelper.startPage(clazzPageQueryDTO.getPage(), clazzPageQueryDTO.getPageSize() );


        Page<Clazz> page = (Page<Clazz>) clazzMapper.pageQuery(clazzPageQueryDTO);




        PageResult<Clazz> pageResult = new PageResult<>(page.getTotal(), page.getResult());


        return pageResult;
    }

    @Override
    public void addClazz(Clazz clazz) {

        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.addClazz_d(clazz);


    }

    @Override
    public Clazz queryById(Integer id) {

        Clazz clazz =  clazzMapper.queryById(id);
        return clazz;
    }

    @Transactional
    @Override
    public void update(Clazz clazz) {
        clazzMapper.update_d(clazz);
    }

    @Override
    public void del(Integer id) {
        clazzMapper.del_d(id);
    }

    @Override
    public List<Clazz> queryAll_s() {
       List<Clazz>  clazz = clazzMapper.queryAll_d();
        return clazz;
    }


}
